fix(TextInput): fall back to theme fontWeight to prevent SIGSEGV on Fabric#4880
Open
isaacrowntree wants to merge 1 commit intocallstack:mainfrom
Open
Conversation
…ide one
Both TextInputOutlined and TextInputFlat destructure `fontWeight` from the
user's `style` prop and spread it after the theme font object:
const { fontWeight } = StyleSheet.flatten(style) || {};
textStyle: { ...font, fontWeight }
When the user doesn't set `fontWeight` in their style, the destructured
value is `undefined`. Spreading `{ ...font, fontWeight: undefined }` then
overrides `font.fontWeight` (e.g. '400' from the theme) with `undefined`.
On React Native's Fabric renderer (New Architecture), this `undefined`
flows through as nil to the native `RCTGetFontWeight` function, which
passes it to `CFStringFind` → `CFStringGetLength` on a NULL pointer →
EXC_BAD_ACCESS (SIGSEGV).
The fix renames the destructured variable to `fontWeightStyle` and uses
nullish coalescing to fall back to the theme font's fontWeight:
const fontWeight = fontWeightStyle ?? font.fontWeight;
This preserves the existing behavior when `fontWeight` IS provided in the
style prop, while preventing the nil crash when it isn't.
|
Hey @isaacrowntree, thank you for your pull request 🤗. The documentation from this branch can be viewed here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
TextInputOutlinedandTextInputFlatdestructurefontWeightfrom the user'sstyleprop and spread it after the theme font object:When the user doesn't provide
fontWeightin their style (the common case — most<TextInput>usage omits it), the destructured value isundefined. Spreading{ ...font, fontWeight: undefined }then overridesfont.fontWeight(e.g.'400'from the theme) withundefined.On React Native's Fabric renderer (New Architecture), this
undefinedflows asnilto the nativeRCTGetFontWeightfunction, which passes it toCFStringFind→CFStringGetLengthon a NULL pointer → EXC_BAD_ACCESS (SIGSEGV).This is a fatal crash that kills the app on any screen with a
<TextInput>that doesn't explicitly setfontWeightin its style prop. Reproduced on iOS with React Native 0.78 + react-native-paper 5.15.0 + Fabric enabled.Related issue
No existing issue — discovered via Crashlytics crash report in production. Native crash stack:
Test plan
<TextInput mode="outlined" />without afontWeightin the style prop → previously crashes on Fabric, now uses theme font's fontWeight<TextInput mode="outlined" style={{ fontWeight: '700' }} />→ still applies the user-provided weight (nullish coalescing only kicks in forundefined/null)TextInputOutlinedandTextInputFlatare patched with the same fix